//*****************************************************************************
// 1. Års eksamen @ Datamatiker - EASJ
// Holmegaard Heldagsskole Administrations system 
// 
// Denne klasse er udarbejdet af: Marc og Kasper
//*****************************************************************************
package view;

import control.ControlUtil;
import model.Personale;
import view.elev.*;

public class Mainscreen extends javax.swing.JFrame {

    private Personale bruger;
    private ControlUtil controlUtil;
    private PersonaleAdminPanel persAdminPanelet;
    private HoldAdminPanel holdAdminPanelet;
    private TrinmaalAdminPanel trinmaalAdminPanelet;
    private FagAdminPanel fagAdminPanelet;
    private OplysningerPanel elevOplysninger;
    private PotentialeKompetancePanel potentailekompetence;
    private EvalueringsPanel evalueringPanelet;
    private OpretPanel opretPanelet;
    private AftalePanel aftalePanelet;
    private LogbogPanel logPanelet;
    private KontaktPersonPanel kpersPanelet;

    public Mainscreen(Personale bruger, ControlUtil conUti) {

        this.bruger = bruger;
        controlUtil = conUti;
        conUti.SetBruger(bruger);

        initComponents();
        opretGUI(Integer.parseInt(this.bruger.getPtype() + ""));
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public void opdaterElevLister() {
        if (Integer.parseInt(bruger.getPtype() + "") != 1) {
            kpersPanelet.hentElever();
        }
        aftalePanelet.hentElever();
        if (Integer.parseInt(bruger.getPtype() + "") != 3) {
            evalueringPanelet.hentElever();
        }
        logPanelet.hentElever();
        elevOplysninger.hentElever();
        opretPanelet.hentElever();
        potentailekompetence.hentElever();
    }

    private void opretGUI(int niveau) {
        final int LAERER = 1;
        final int PAEDAGOG = 2;
        final int SEKRETAER = 3;
        final int ADMIN = 4;
        switch (niveau) {
            case LAERER:
                laererGUI();
                break;
            case PAEDAGOG:
                paedagogGUI();
                break;
            case SEKRETAER:
                sekretaerGUI();
                break;
            case ADMIN:
                adminGUI();
                break;
        }
        opdaterElevLister();
    }

    private void laererGUI() {
        persAdminGUI();
        holdAdminGUI();
        trinmaalAdminGUI();
        fagAdminGUI();
        elevOplysningGUI();
        elevFagGUI();
        elevOpretGUI();
        elevAftaleGUI();
        elevLogbogGUI();
        elevEvalueringGUI();
        elevPane.remove(kpersContainer);
    }

    private void paedagogGUI() {
        elevOplysningGUI();
        elevFagGUI();
        elevAftaleGUI();
        elevLogbogGUI();
        elevKPersGUI();
        elevOpretGUI();
        elevEvalueringGUI();
        jTabbedPane1.remove(persAdminContainer);
        jTabbedPane1.remove(holdAdminContainer);
        jTabbedPane1.remove(fagAdminContainer);
    }

    private void sekretaerGUI() {
        persAdminGUI();
        holdAdminGUI();
        fagAdminGUI();
        elevOplysningGUI();
        elevFagGUI();
        elevOpretGUI();
        elevAftaleGUI();
        elevLogbogGUI();
        elevKPersGUI();
        jTabbedPane1.remove(evalueringContainer);
        jTabbedPane1.remove(trinmaalContainer);
    }

    private void adminGUI() {
        persAdminGUI();
        holdAdminGUI();
        trinmaalAdminGUI();
        fagAdminGUI();
        elevOplysningGUI();
        elevFagGUI();
        elevOpretGUI();
        elevAftaleGUI();
        elevLogbogGUI();
        elevKPersGUI();
        elevEvalueringGUI();
    }

    private void persAdminGUI() {
        persAdminPanelet = new PersonaleAdminPanel(controlUtil);
        persAdminPanelet.setBounds(0, 0, persAdminContainer.getWidth(), persAdminContainer.getHeight());
        persAdminContainer.add(persAdminPanelet);
        persAdminContainer.validate();
    }

    private void holdAdminGUI() {
        holdAdminPanelet = new HoldAdminPanel(controlUtil);
        holdAdminPanelet.setBounds(0, 0, holdAdminContainer.getWidth(), holdAdminContainer.getHeight());
        holdAdminContainer.add(holdAdminPanelet);
        holdAdminContainer.validate();
    }

    private void trinmaalAdminGUI() {
        trinmaalAdminPanelet = new TrinmaalAdminPanel(controlUtil);
        trinmaalAdminPanelet.setBounds(0, 0, trinmaalContainer.getWidth(), trinmaalContainer.getHeight());
        trinmaalContainer.add(trinmaalAdminPanelet);
        trinmaalContainer.validate();
    }

    private void fagAdminGUI() {
        fagAdminPanelet = new FagAdminPanel(controlUtil);
        fagAdminPanelet.setBounds(0, 0, fagAdminContainer.getWidth(), fagAdminContainer.getHeight());
        fagAdminContainer.add(fagAdminPanelet);
        fagAdminContainer.validate();
    }

    private void elevOplysningGUI() {
        elevOplysninger = new OplysningerPanel(controlUtil);
        elevOplysninger.setBounds(0, 0, potentialeKompetenceContainer.getWidth(), potentialeKompetenceContainer.getHeight());
        oplysningContainer.add(elevOplysninger);
        oplysningContainer.validate();
    }

    private void elevFagGUI() {
        potentailekompetence = new PotentialeKompetancePanel(controlUtil);
        potentailekompetence.setBounds(0, 0, potentialeKompetenceContainer.getWidth(), potentialeKompetenceContainer.getHeight());
        potentialeKompetenceContainer.add(potentailekompetence);
        potentialeKompetenceContainer.validate();
    }

    private void elevEvalueringGUI() {
        evalueringPanelet = new EvalueringsPanel(controlUtil);
        evalueringPanelet.setBounds(0, 0, evalueringContainer.getWidth(), evalueringContainer.getHeight());
        evalueringContainer.add(evalueringPanelet);
        evalueringContainer.validate();
    }

    private void elevOpretGUI() {
        opretPanelet = new OpretPanel(controlUtil);
        opretPanelet.setBounds(0, 0, opretRedElevContainer.getWidth(), opretRedElevContainer.getHeight());
        opretRedElevContainer.add(opretPanelet);
        opretRedElevContainer.validate();
    }

    private void elevAftaleGUI() {
        aftalePanelet = new AftalePanel(controlUtil);
        aftalePanelet.setBounds(0, 0, aftaleContainer.getWidth(), aftaleContainer.getHeight());
        aftaleContainer.add(aftalePanelet);
        aftaleContainer.validate();
    }

    private void elevLogbogGUI() {
        logPanelet = new LogbogPanel(controlUtil);
        logPanelet.setBounds(0, 0, logbogAftaleContainer.getWidth(), logbogAftaleContainer.getHeight());
        logbogAftaleContainer.add(logPanelet);
        logbogAftaleContainer.validate();
    }

    private void elevKPersGUI() {
        kpersPanelet = new KontaktPersonPanel(controlUtil);
        kpersPanelet.setBounds(0, 0, kpersContainer.getWidth(), kpersContainer.getHeight());
        kpersContainer.add(kpersPanelet);
        kpersContainer.validate();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        elevAdminContainer = new javax.swing.JPanel();
        elevPane = new javax.swing.JTabbedPane();
        oplysningContainer = new javax.swing.JPanel();
        kpersContainer = new javax.swing.JPanel();
        potentialeKompetenceContainer = new javax.swing.JPanel();
        evalueringContainer = new javax.swing.JPanel();
        opretRedElevContainer = new javax.swing.JPanel();
        logbogAftaleContainer = new javax.swing.JPanel();
        aftaleContainer = new javax.swing.JPanel();
        persAdminContainer = new javax.swing.JPanel();
        holdAdminContainer = new javax.swing.JPanel();
        fagAdminContainer = new javax.swing.JPanel();
        trinmaalContainer = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Holmegaard Heldagsskole Administration - " + controlUtil.getPersonaleHandler().ptypeTilTekst(bruger.getPtype()) +" - "+ bruger);
        setBounds(new java.awt.Rectangle(150, 10, 1024, 700));
        setMinimumSize(new java.awt.Dimension(1024, 700));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        getContentPane().setLayout(null);

        jTabbedPane1.setMinimumSize(new java.awt.Dimension(1024, 728));
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(1024, 728));

        elevPane.setAlignmentX(0.2F);
        elevPane.setAlignmentY(0.2F);
        elevPane.setMinimumSize(new java.awt.Dimension(105, 200));
        elevPane.setPreferredSize(new java.awt.Dimension(105, 200));

        oplysningContainer.setMinimumSize(new java.awt.Dimension(1024, 600));
        oplysningContainer.setLayout(null);
        elevPane.addTab("   Vis Elev   ", oplysningContainer);

        kpersContainer.setLayout(null);
        elevPane.addTab("   Kontaktpersoner   ", kpersContainer);

        potentialeKompetenceContainer.setLayout(null);
        elevPane.addTab("Potentialer/Kompetencer", potentialeKompetenceContainer);

        javax.swing.GroupLayout evalueringContainerLayout = new javax.swing.GroupLayout(evalueringContainer);
        evalueringContainer.setLayout(evalueringContainerLayout);
        evalueringContainerLayout.setHorizontalGroup(
            evalueringContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1014, Short.MAX_VALUE)
        );
        evalueringContainerLayout.setVerticalGroup(
            evalueringContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 672, Short.MAX_VALUE)
        );

        elevPane.addTab("Evaluering", evalueringContainer);

        opretRedElevContainer.setLayout(null);
        elevPane.addTab("Opret/Rediger Elev", opretRedElevContainer);

        logbogAftaleContainer.setLayout(null);
        elevPane.addTab("     Logbog     ", logbogAftaleContainer);

        aftaleContainer.setLayout(null);
        elevPane.addTab("  Aftaleliste  ", aftaleContainer);

        javax.swing.GroupLayout elevAdminContainerLayout = new javax.swing.GroupLayout(elevAdminContainer);
        elevAdminContainer.setLayout(elevAdminContainerLayout);
        elevAdminContainerLayout.setHorizontalGroup(
            elevAdminContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(elevPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1019, Short.MAX_VALUE)
        );
        elevAdminContainerLayout.setVerticalGroup(
            elevAdminContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(elevPane, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("        Elever       ", elevAdminContainer);

        persAdminContainer.setLayout(null);
        jTabbedPane1.addTab("     Personale     ", persAdminContainer);

        holdAdminContainer.setMaximumSize(new java.awt.Dimension(1024, 700));
        holdAdminContainer.setMinimumSize(new java.awt.Dimension(1024, 700));
        holdAdminContainer.setName(""); // NOI18N
        holdAdminContainer.setLayout(null);
        jTabbedPane1.addTab("        Hold        ", holdAdminContainer);

        fagAdminContainer.setLayout(null);
        jTabbedPane1.addTab("         Fag         ", fagAdminContainer);

        trinmaalContainer.setLayout(null);
        jTabbedPane1.addTab("      Trinmål      ", trinmaalContainer);

        getContentPane().add(jTabbedPane1);
        jTabbedPane1.setBounds(0, 0, 1024, 728);

        jMenu1.setText("Filer");

        jMenuItem1.setText("Log ud");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem3.setText("Luk Programmet");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Hjælp");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        dispose();

    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        controlUtil.getSession().close();
        System.exit(0);

    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        dispose();
    }//GEN-LAST:event_formWindowClosed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aftaleContainer;
    private javax.swing.JPanel elevAdminContainer;
    private javax.swing.JTabbedPane elevPane;
    private javax.swing.JPanel evalueringContainer;
    private javax.swing.JPanel fagAdminContainer;
    private javax.swing.JPanel holdAdminContainer;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel kpersContainer;
    private javax.swing.JPanel logbogAftaleContainer;
    private javax.swing.JPanel oplysningContainer;
    private javax.swing.JPanel opretRedElevContainer;
    private javax.swing.JPanel persAdminContainer;
    private javax.swing.JPanel potentialeKompetenceContainer;
    private javax.swing.JPanel trinmaalContainer;
    // End of variables declaration//GEN-END:variables
}
